---------------------
Urthwurm source files
---------------------

What is this
------------
These are the source files (Turbo Pascal 7.0) for the game UrthWurm created by
BdR. It should simply compile, provided that you have Turbo Pascal, by typing:

tpc -b urthwurm

Make sure you have all the source files, they are:
Bdrcomon.pas
Gamecode.pas
Grafdata.pas
Graphics.pas
Hiscores.pas
Keyboard.pas
Menucode.pas
urthwurm.pas
makedata\makedata.pas
makedata\pcx_view.pas
makedata\24bits.bmp
makedata\8bits.pcx

The basic idea
--------------

Although there are comments in the pascal files, i'll outline how it works so
you have a basic idea. The main-game-loop simply draws 1 line (of a pattern)
on the right-hand side of the screen, then 'erases' a small piece (this is
what becomes the tunnel) and it also draws the snake and then it shifts the
entire screen 1 pixel to the left. This is basically it. 

It checks if the player hit something by looking at the pixels on the position
the player will be next. If all pixels are of a none-pattern color (i.e.
higher than color number 235) then it's okay, if not than it's game-over.

The sinus movement of the urthwurm is done using a lookup-table which i made
with a pascal program. A lookup table saves calculation time, which is good
when running on slower pc's.

Notes on the source files
-------------------------

Bdrcomon.pas: Has some functions i use often. The HiddenString function is
used so that some text strings can not be seen when you open the final .EXE
file in a hex-editor.

Gamecode.pas: This unit contains the game functionality.

Grafdata.pas: This unit contains the graphics. I wanted all the graphic-data
to be inside the .EXE file (instead of a separate datafile) so i use pascal
arrays and also assembler DB (DataByte) to store the graphics. If you declare a
pascal procedure and only use DB-assembler statements, you can treat a pointer
to that procedure as if it is a data-pointer.

Graphics.pas: These are the graphics functions. Some of it is in assembler to
speed up the code, so that it also works on slower pc's. A virtual screen is
used becuase drawing to the VGA memory (segment A000) is slow. Drawing to the
virtual screen, then shifting it 1 pixel to the left and then copying the
entire screen to VGA segment (which seems inefficient) is infact faster then
doing these things directly to the VGA memory segment. Note that the V_Flip
procedure uses some super-fast assembler code (i copied that procedure from
some page on the internet).

Hiscores.pas: This unit contains the functions to load and save the hiscores.

Keyboard.pas: This unit was made by Steven H. Don (http://shd.cjb.net/) I used
it to take over the standard keyboard handler (only during the main gameloop),
so that i can check whether or not the spacebar is pressed, instead of
space-characters being typed.

Menucode.pas: This unit contains all the code for the main menu.

Smallcrt.pas: A unit that replaces the standard CRT unit, also by Steven H.
Don. If you use CRT you get the famous "runtime error 200". I only use
SMALLCRT for the functions KEYPRESSED and READKEY.

urthwurm.pas: This is the main program.

Notes on the graphics
---------------------

If you want to change the graphics, note that you cannot use the last 20
colors of the VGA palet. These colors are used to create the background
effect in the game (the grey bars). I used Paintshop Pro (version 6) to create
the graphics. First i made a 24 bit version, then i chose Colors->Decrease
colors depth->X colors and then chose 235 colors (255 minus 20). Before you do
this, you should create some areas and fill them up with the 10 patterns
(using the filler-tool). If you do not do this, the patterns use up little
space in the image (16x16 pixels) and thus Paintshop Pro reserves fewer of the
235 colors for these patterns, and more for the logo (which is bigger).

You can change the font as long as you keep the characters 8x8 pixels (this is
a fixed-size in the program).

After you edited the picture and saved it as a 256 color PCX file, you can run
MAKEDATA.PAS using Turbo Pascal (and maybe edit it a bit if, for example, you
made the logo bigger or smaller). It will create a GRAFDATA.PAS file which has
the pascal arrays and assembler procedure with the graphics as data, you can
cut-and-paste this data into the correct GRAFDATA.PAS file.

Bas de Reuver, june 2002